{%
set langstr = '';
%}
<script>
    $(function () {
        //$("#userEmail").html(window.user.email)
        layui.use(['form', 'layedit', 'laydate'], function(){
            var form = layui.form
                ,layer = layui.layer
            //自定义验证规则
            form.verify({
                password: function(value){
                    if(value.length < 1){
                        return '请输入旧密码';
                    }
                }
                ,new_password: function(value){
                    if(value.length < 1){
                        return '请输入新密码';
                    }
                    if(!passwordReg.test(value)){
                        return passwordErrorMsg;
                    }
                }
                ,con_password: function(value){
                    if(value.length < 1){
                        return '请输入确认新密码';
                    }
                    var new_password = $('#new_password').val();
                    if(value != new_password){
                        return '两次输入的密码不一致!';
                    }
                }
            });

            //监听提交
            form.on('submit(resetPwdSubmit)', function(data){
                resetPwd(data.field)
                return false;
            });


        });


    })
    function modifyPwd (){
        layer.open({
            type: 1,
            title: "修改密码",
            area: ['400px','auto'], //宽高
            content: $("#resetPwd"),

        });
    }
    function resetPwd(data){

        var params = {
            password : data.password,
            new_password:data.new_password,
        }
        $.post("/sale/update/password",params,function(result){
            if(result.status == 200){
                delCookie("token")
                delCookie("user")
                layer.msg("重置密码成功，请重新登录",{icon:1, time: 1000,},function () {
                    window.location.href = "/sale/login";
                })

            }else{
                layer.msg(result.msg,{icon:2})
            }

        })
    }
    function logout(){
        layer.confirm('确认退出登录？', {
            btn: ['确认','取消'] //按钮
        }, function(){
            $.post("/sale/logout",{},function(result){
                if(result.status == 200){
                    delCookie("saletoken")
                   delCookie("user")
                    layer.msg("安全退出",{icon:1, time: 1000,},function () {
                      window.location.href = "/sale/login"
                    },100)

                }

            })

        }, function(){

        });

    }
</script>
<div id="header">
    <div class="header_holder">
        {% if langstr === "cn" || langstr === "" %}
            <a class="logo" href="http://www.middleforex.com/"></a>
        {% else %}
            <a class="enlogo" href="http://en.middleforex.com/"></a>
        {% endif %}


        <ul class="account">
            <li style="font-size: 14px;color:#fff;">
                <span id="userEmail"></span>
            </li>
            <li>
                <div class="modifypwd" style="cursor:pointer" onclick="modifyPwd();">
                    <a href="javascript:void(0);" >修改密码</a>
                </div>
            </li>
            <li>

                <div class="logout" style="cursor:pointer" onclick="logout()">
                    <a >{{ common.logout || '退出登录' }}</a>
                </div>
            </li>
        </ul>
    </div>
</div>



<div id="resetPwd" style="display: none">
    <div class="form" style="padding:20px;">

        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" lay-verify="password" autocomplete="off"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password"  id = "new_password" name="new_password" lay-verify="new_password" autocomplete="off"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="con_password" lay-verify="con_password" autocomplete="off"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="resetPwdSubmit" onclick="return false;">提交</button>
                </div>
            </div>
        </form>

    </div>

</div>